<meta content="text/html; charset=UTF-8; X-Content-Type-Options=nosniff" http-equiv="Content-Type" />
<script src="js/smartstream.js"></script>
<script src="js/smartstream.main.topics.js"></script>
<script src="js/stream.api.js"></script>
<script src="js/tag.api.js"></script>
<script src="js/WorkflowactionScript.js"></script>


<style type="text/css">
    #ss_panel_top {text-align: center; background-color: #e5e5e5; line-height:20px;}
    #ss_menubar_filter {color: black; }
    #ss_menubar_filter .k-animation-container{width: 87px !important; }
    #ss_menubar_filter .k-animation-container ul{ width: 87px !important;}
    .ss_line_height_0 {line-height: 0; }
    .ss_vertical_align_middle {vertical-align: middle; }
    .ss_content {color:#595959; line-height:14px; }
    #ss_topics_row_right_top_row_tag {color:#a6a6a6; }
    #ss_search_result_back {color:#00aaff;}
    .ss_lh_10{line-height:15px; }
    .ss_lh_11{line-height:11px; }
    .ss_lh_15{line-height:15px; }
    .ss_lh_16{line-height:16px; }
    .ss_lh_17{line-height:17px; }
    .ss_lh_20{line-height:20px; }
    .ss_lh_25{line-height:25px;}
    .ss_btn_delete {color: #d94c4c; }
    /*.ss_div_show {display: block; }*/
    .ss_div_hide {display: none; }
    .ss_border_1{border-bottom:1px solid #f2f2f2;}
    .ss_border_2{border-bottom:1px solid #e5e5e5;}
    .ss_border_white{border-bottom:1px solid #ffffff;}
    .ss_btn{padding: 0 10px;}
    .ss_delete_color{color:#d94c4c!important;text-decoration: none;}
    .ss_bg {background-color: #9f9f9f;}
    .ss_comments_bg {background-color: #efefef;}
    .ss_a {color: #595959; text-decoration:none;}
    .ss_tag_a {color: #A6A6A6;text-decoration:none;}

    .ss_disabled {disabled:true;}

    #ss_topic_append_comment table{height: 80px;background: #F2F2F2;}
    #ss_topic_append_comment table .k-editable-area{height: 40px; border-color: #efefef;}
    #ss_topic_append_comment table .k-editor-toolbar a {background: #F2F2F2;}
    #ss_topic_append_comment .k-editor-widget .k-group-end span.k-state-default {
    background: none repeat scroll 0 0 rgba(0, 0, 0, 0) !important;
}
    .ss_topic_hand{cursor:pointer;}
    .redback{background-color: red;}
    .divScrollBar{position:absolute;opacity:1; filter:Alpha(opacity=100); z-index:999;}
    .divScrollBar:hover{opacity:1; filter:Alpha(opacity=100);}
    .divScrollBar div{background-color:#d9d9d9; height:18px; width:18px; overflow:hidden; position:absolute; left:0px; top:0px; cursor:pointer; border-radius:5px;}
    .valign_center{vertical-align:middle}
    #smartstream_min_view table{width:207px;border-collapse:collapse;border-spacing:0;table-layout:fixed}
    #smartstream_min_view table tbody tr td{vertical-align:top;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
    #smartstream_min_view table tbody tr td div{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
    #smartstream_max_view table{width:721px;border-collapse:collapse;border-spacing:0;table-layout:fixed}
    #smartstream_max_view table tbody tr td{vertical-align:top}
    #smartstream_max_view table tbody tr td div{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
    #smartstream_max_view table tbody tr td div i{margin:3px}
    .ss_topic_div_comments_text ul{ margin-left: 12px;}
    .ss_topic_div_comments_text ol{ margin-left: 15px;}

    /*//*/
    /*//text-overflow: ellipsis;*/
    .ss_fixedwidth{width: 82px !important; overflow: hidden; height: 16px !important; padding-right: 5px;white-space:nowrap;text-overflow:ellipsis;}
    .ss_controlIcon{ float: right;  margin: -8px 2px 0px 2px !important;}


    #ss_topic_select_file .k-upload-files{display: none;}
    #ss_topic_select_file .k-file{display: none;}
    /*kendo upload*/
    #ss_topic_select_file .k-button{min-width:0; width:45px; padding:0;margin:0;}
    #ss_topic_select_file .k-upload-button{background-color: #6cbf43!important;float:right;}
    #ss_topic_select_file .k-upload-button span{height:17px; line-height:17px; font-size:9px;}

    #ss_topic_select_file .k-upload-files{clear:both; min-height:41px;display: none; padding-top:10px;}
    #ss_topic_select_file .k-upload-files li{min-width:42px; max-width:42px; padding:0; border:none; float:left; margin-right:12px; font-size:12px; height:48px;}

    #ss_topic_select_file .k-upload-status{left:16px; top:-3px; line-height:0;}
    #ss_topic_select_file .k-upload-status span{background:url("imgs/delete.png") no-repeat;overflow:visible;}

    #ss_topic_select_file .k-i-pdf{height:40px; width:40px; background:url("imgs/pdfIcon40.png") no-repeat!important; display: block; }
    #ss_topic_select_file .k-i-txt{height:40px; width:40px; background:url("imgs/txt40.png") no-repeat!important; display: block; }
    #ss_topic_select_file .k-i-doc, .k-i-docx {height:40px; width:40px; background:url("imgs/docIcon40.png") no-repeat!important; display: block; }
    #ss_topic_select_file .k-i-xls, .k-i-xlsx {height:40px; width:40px; background:url("imgs/xlsIcon40.png") no-repeat!important; display: block; }
    #ss_topic_select_file .k-i-ppt, .k-i-pptx {height:40px; width:40px; background:url("imgs/ppt40.png") no-repeat!important; display: block; }
    #ss_topic_select_file .k-i-zip{height:40px; width:40px; background:url("imgs/zip40.png") no-repeat!important; display: block; }
    #ss_topic_select_file .k-i-jpeg, .k-i-jpg, .k-i-png, .k-i-gif, .k-i-bmp, .k-i-tiff {height:40px; width:40px; background:url("imgs/img40.png") no-repeat!important; display: block; }
    #ss_topic_select_file .k-upload-button-disable{background-color: #f4f4f4!important;float:right;color:#b7b7b7;}

    #ss_topic_select_file .k-upload .k-upload-files li{
    background:transparent !important;
    }

    #ss_topic_began {
        position: absolute;
        top:50px;
        left:15px;
        display: none;
    }

    #ss_load_view {
        position: absolute;
        top:50px;
        left:15px;
        display: none;
    }

</style>
<div class="wp_w_256 " id="ss_index_window">
        <div id="ss_panel_top" class="wp_h_20 wp_fz_14 wp_pl_25 "></div>
        <div id="ss_panel_functions" class="wp_mt_10 wp_h_16">
            <div id="filterMenu" class="left wp_ml_25">
                <ul id="ss_menubar_filter" class="wp_fz_10 wp_h_16 wp_w_82">
                </ul>
            </div>
            <div id="ss_menubar_search" class="wp_mr_10 right">
                <a href="#" id="ss_menubar_search_btn"><i class="main_common_j_11_11"></i></a>
            </div>
            <div id="ss_menubar_share" class="wp_mr_20 wp_mt_ne2 right">
                <button id="ss_menubar_share_btn" class="wp_fz_10 wp_w_38 ss_lh_16 ss_topic_detail_hand" style="text-align: center;
    vertical-align: middle;"></button>
                <div id="ss_topic_began" ><img src="imgs/beganSmartSream.png"></img></div>
            </div>
            <div id="ss_menubar_initiator" class="wp_mr_20 wp_mt_ne4 right">
                <a href="#" id="ss_menubar_initiator_btn" class="wp_fz_11 "></a>
            </div>
            <div id="ss_menubar_time" class="wp_mr_20 right">
                <a href="#" id="ss_menubar_time_btn" class="wp_fz_11 "></a>
            </div>
        </div>
        <div id="ss_search_view" class="wp_w_768 wp_h_30 wp_mt_15 ss_border_2"></div>
        <div id="ss_search_view_lable" class="wp_w_768 wp_h_20 wp_mt_10"></div>
        <div id="ss_topic_user_list_div">
            <div id="ss_topic_user_list_window">
                <div id="ss_topic_user_list_window_content" class="wp_w_384 wp_ml_15 wp_mr_15 wp_mb_10 wp_mt_ne10" data-template="ss_topic_user_list_template" data-bind="source:ss_topic_detail_like_user_list"></div>
            </div>
        </div>
        
        <div id="ss_view" class="wp_mt_5 wp_w_768" style="overflow-y:scroll;">
            
        </div>
    
        <div id="ss_load_view" >
            <img src="imgs/spinner.gif"></img>
        </div>



        <div id="ss_popup_view" class="ss_div_hide">
            <div class="row"><span style=" text-align: center;" class="col_1_1 wp_dynimac_text wp_mt_10 wp_mb_10" data-bind="text: _content"></span></div>
            <div class="row">
                <div class="col_1_2">
                    <button class="right btn btn-grey wp_w_58 wp_h_20 wp_mr_20 left wp_fz_10" data-bind="text: _cancel,click: onCancel"></button>

                </div>
                <div class="col_1_2">
                    <button class="left btn btn-crimson wp_w_58 wp_h_20 left wp_fz_10" data-bind="text: _yes,click: onYes"></button>
                </div>
            </div>
        </div>

</div>

<script type="text/x-kendo-template" id="ss_panel_top_tmpl">
    #: ss #<i id="ss_panel_top_resize" class="main_common_i_11_11 wp_mt_3 wp_mr_3 right ss_topic_detail_hand" title="Expand"></i>
</script>



<script type="text/x-kendo-template" id="ss_menubar_time_btn_tmpl">
    #: time #<i id="ss_menubar_time_icon" class="wp_ml_3 wp_mt_3 right main_icon_e_6_8"></i>
</script>

<script type="text/x-kendo-template" id="ss_menubar_initiator_btn_tmpl">
    #: initiator #<i id="ss_menubar_initiator_icon" class="wp_mt_9 wp_ml_3 right main_icon_f_6_8"></i>
</script>

<script type="text/x-kendo-template" id="ss_menubar_share_btn_tmpl">
    #: share #
</script>

<script type="text/x-kendo-template" id="ss_search_view_tmpl">
    <span id="ss_search_keywords_label" class="left wp_ml_25 wp_fz_11 wp_mt_3">#: keywords #</span>
    <div style="border: \#D8D8D8 1px solid; background-color: \#ffffff" class="left wp_ml_10 wp_w_252 wp_h_20">
        <input type="text" id="ss_search_keywords_input" maxlength="2000" style="border:0px;" class="left wp_h_20 wp_w_235">
        <i class="main_common_j_11_11 left wp_ml_1 wp_mt_5"></i>
    </div>
    <span id="ss_search_comm_label" class="ss_div_hide left wp_ml_20 wp_fz_11 wp_mt_3">#: communities #</span>
    <input type="text" id="ss_search_comm_input" class="ss_div_hide left wp_ml_10 wp_h_20 wp_w_125"/>
    <span id="ss_search_date_from_label" class="ss_div_hide left wp_ml_20 wp_mt_3 wp_fz_11">#: time #</span>
    <input id="ss_search_date_from" class="ss_div_hide left wp_ml_5 wp_h_20 wp_w_72"/>
    <span id="ss_search_date_to_label" class="ss_div_hide left wp_ml_5 wp_mt_3 wp_fz_11">#: to #</span>
    <input id="ss_search_date_to" class="ss_div_hide left wp_ml_5 wp_h_20 wp_w_72"/>
    <button style="display: none;" id="ss_search_btn" class="right btn wp_w_50 wp_mr_25 wp_h_20 wp_fz_11 ss_topic_detail_hand">#: search #</button>
</script>

<script type="text/x-kendo-template" id="ss_search_view_lable_tmpl">
    <a href='\#' id="ss_search_result_back" class="left wp_ml_25 wp_fz_12">#: backToAll #</a>
    <span id="ss_search_result_label" class="left wp_fz_12">&nbsp;&gt;&nbsp;#: resultNum #&nbsp;#: resultsFor #&nbsp;#: keyword_input #</span>
</script>


<script type="text/javascript">
    //max topic template
    var smartstream_head = '<script id="ss_tmpl_topics_max" type="text\/x-kendo-template">';
    var smartstream_end = '<\/script>';
    var smartstream_hr = '<hr class="ss_border_1" \/>'
    var smartstream_div_head = '<div class="ss_border_1">';
    var smartstream_div_end = '<\/div>';
    var smartstream_template;
    var smartstream_topics_tmpl = $.getExtFile("html/smartstream.main.topics.max.tmpl.htm");
    var smartstream_commets_tmpl = $.getExtFile("html/smartstream.main.comments.tmpl.htm");
    smartstream_template = smartstream_head + smartstream_div_head + smartstream_topics_tmpl + smartstream_div_end + smartstream_end;
    $("body").append(smartstream_template);

    smartstream_head = '<script id="ss_tmpl_comments" type="text\/x-kendo-template">';
    smartstream_template = smartstream_head + smartstream_commets_tmpl + smartstream_end;
    $("body").append(smartstream_template);
    //min topic template
    smartstream_head = '<script type="text\/x-kendo-template" id="ss_tmpl_topics_min">';
    var smartstream_topics_tmpl = $.getExtFile("html/smartstream.main.topics.min.tmpl.htm");
    smartstream_template = smartstream_head + smartstream_topics_tmpl + smartstream_end;
    $("body").append(smartstream_template);


</script>


<script type="text/x-kendo-template" id="ss_topic_user_list_template">
    <div class="wp_w_162 wp_mb_20 wp_w_354">
        <img class="left wp_w_20 wp_h_20 ss_topic_hand"
             data-bind="attr:{src:UserImageURL},click:onLikeUserClick" onerror="onDefaultThumbnailWanted(this, 'U20')">
        <span class="wp_fz_12 wp_ml_15 wp_mt_ne3 wp_w_300 left ss_topic_hand" data-bind="text: UserName,click:onLikeUserClick"></span>
        <div class="clear"></div>
    </div>
</script>


<script>
    function ss_viewport() {
        var e = window, a = 'inner';
        if (!('innerWidth' in window )) {
            a = 'client';
            e = document.documentElement || document.body;
        }
        return { width : e[ a+'Width' ] , height : e[ a+'Height' ] };
    }
    $(function(){

        

        var ss_view_height = ss_viewport().height;//getDocHeight();
        var ss_view = $('#ss_view');
        var filterMenu_i = 1,filterMenu_menu = [];
        var useragent = Workport.getBrowser();
        ss_view.css({
            "height":ss_view_height
        });
        if(useragent != 'ipad'){
            ss_view.slimScroll({
                height: ss_view_height-110,
                width: 256,
                wheelStep: 20,
                disableFadeOut:true
            });
        }
        $("#ss_menubar_time").hide();
        $("#ss_menubar_initiator").hide();
        $("#ss_search_view").hide();
        $("#ss_search_view_lable").hide();
        $("#ss_search_keywords_input").val("");
        // title
        var ss_panel_top_tmpl = kendo.template($('#ss_panel_top_tmpl').html());
        $('#ss_panel_top').html(ss_panel_top_tmpl({ ss: "Smart Stream" }));

        //zoom in and out.
        function smartstream_tmpl_zoomin_cb() {

            $("#ss_index_window").toggleClass("wp_w_768");
            $("#ss_panel_top_resize").toggleClass("main_common_i_11_11 main_common_k_13_13");
            $("#ss_panel_top_resize").attr("title",'Collapse');
            /** resize the search icon's margin right **/
            $("#ss_menubar_search").toggleClass("wp_mr_15");

            // hide or show some components
            $("#ss_menubar_time").toggle();
            // $("#ss_menubar_initiator").toggle();

            SmartStream.setHideComponent(true);

            homepage_resize(768,1);
            $('#ss_view').parent().css({
                "width":768
            });

            $('#ss_view').css({
                "width":768
            });

            bindListView(true,true);
            SmartStream.setHideComponent(false);


        }
        function smartstream_tmpl_zoomout_cb() {
            $("#ss_index_window").toggleClass("wp_w_768");
            $("#ss_panel_top_resize").toggleClass("main_common_i_11_11 main_common_k_13_13");
            $("#ss_panel_top_resize").attr("title",'Expand');
            /** resize the search icon's margin right **/
            $("#ss_menubar_search").toggleClass("wp_mr_15");

            // hide or show some components
            $("#ss_menubar_time").toggle();
            // $("#ss_menubar_initiator").toggle();


            SmartStream.setHideComponent(false);

            homepage_resize(256,1);
            $("#ss_search_view").hide();
            $("#ss_search_view_lable").hide();
            $("#ss_search_keywords_input").val("");
            $("#ss_search_view_lable").empty();
            $('#ss_view').parent().css({
                "width":256
            });

            $('#ss_view').css({
                "width":256
            });
            ///////////////////////////////////////
            bindListView(false,true);
            SmartStream.setHideComponent(true);
            ///////////////////////////////////////
            if($("#ss_menubar_share_btn").data('kendoTooltip'))
                $("#ss_menubar_share_btn").data('kendoTooltip').hide();

        }
        HomePage_Scrollable.registerZoomCallback(WPMoudleManager.getModule('smartstream').index,smartstream_tmpl_zoomin_cb, smartstream_tmpl_zoomout_cb);

        function ss_resize(e){
            HomePage_Scrollable.zoom(WPMoudleManager.getModule('smartstream').index);
            return;
        }
        //fitler begin
        function onSelect(e) {
            $("#ss_search_view").hide();
            $("#ss_search_view_lable").hide();
            $("#ss_search_keywords_input").val("");
            $("#ss_search_view_lable").empty();
            var item = $(e.item);
            var _txt = item.find('span').text() ;

            if(_txt.length < 20){

                $('#ss_menubar_filter').find('span:first').html('<span class="k-icon k-i-arrow-s right " style="margin:5px 2px;"></span>'+(_txt == 'Get All' ? 'Filter Posts' : _txt));
            }
            var classes = item.attr('class').split(' ');
            var csel = 0;
            if($.inArray('.v0',classes) !== -1){

            }else{
                $.map(classes,function(c){
                if(c.indexOf('.v') === 0){
                    $.map(filterMenu_menu,function(_item){
                        if(c == _item.id){
                            csel =  _item.val;
                        }
                    });
                    }
                });
            }
            if((csel == 0 && _txt =='Get All' ) || (csel != 0 && _txt != 'Filter Posts')){
                    SmartStream.setFilterParam(csel);
                    SmartStream.refreshListView(true,true);//no cache
                    SmartStream.setIsMoved(false);
            }
        }
         var filterMenu_ds ={
            text:"Filter Posts",
            value:"12",
            cssClass:'v'+filterMenu_i,
            items:[{text:'Get All',value:0,cssClass:'.v0'}]
        };
        Workport.StreamAPI.getFilter(function(_d){
            var tofun = [];
            var toset = ['Following','My Posts','Bookmark','Pending Items'];
            $.map(_d,function(_item){
                tofun.push(_item.FilterName);
                filterMenu_i++;
                filterMenu_ds.items.push({text:_item.FilterName,value:_item.FilterID, cssClass:'.v'+filterMenu_i});
                if($.inArray(_item.FilterName,toset) !== -1){
                    var i = 0;
                    switch(_item.FilterName){
                        case 'Following':
                            i = 4; break;
                        case 'My Posts':
                            i = 5; break;
                        case 'Bookmark':
                            i = 6; break;
                        case 'Pending Items':
                            i = 3; break;
                    }
                    filterMenu_menu.push({id:'.v'+filterMenu_i,val:i});
                }
            });

            Workport.StreamAPI.getEntities(function(_id){
                $.map(filterMenu_ds.items,function(_item){
                        if('Notifications' == _item.text){
                            _item.items=[];
                             $.map(_id,function(_entity){
                                filterMenu_i++;
                                _item.items.push({text:_entity.EntityName,value:_entity.EntityID,cssClass:'.v'+filterMenu_i});
                                filterMenu_menu.push({id:'.v'+filterMenu_i,val:'2*'+_entity.EntityName});
                             });
                        }
                });
                 $("#ss_menubar_filter").kendoMenu({
                    dataSource:filterMenu_ds,
                    select:onSelect
                });
                $('#ss_menubar_filter').find('span:eq(0)').addClass('ss_fixedwidth');
                $('#ss_menubar_filter').find('span:eq(0)>span').addClass('ss_controlIcon');
            });
        });
        //end fitler

        // resize button
        $("#ss_panel_top_resize").bind({
            click:ss_resize
        });

        // Search button
        $("#ss_menubar_search_btn").bind({
            click:function(){
                if(SmartStream.getHideComponent()){
                    ss_resize();
                }

                $("#ss_search_view").toggle();
                $("#ss_search_view_lable").toggle();
                $("#ss_search_keywords_input").val("");
                $("#ss_search_view_lable").empty();
                if($('#ss_search_view').attr("style")!="display: block;")
                    SmartStream.refreshListView(false,true);//cache
            }
        });

        // Share button
        var ss_menubar_share_btn_tmpl = kendo.template($('#ss_menubar_share_btn_tmpl').html());
        $('#ss_menubar_share_btn').html(ss_menubar_share_btn_tmpl({ share: "Share" }));
        $("#ss_menubar_share_btn").bind({
            click:function(){
                smartstreamShareWinFunc.share_win_create(function(){
                    SmartStream.refreshListView(true,false);//cache
                    SmartStream.setIsMoved(false);
               });
            }
        });

        // Initiator button
        var ss_menubar_initiator_btn_tmpl = kendo.template($('#ss_menubar_initiator_btn_tmpl').html());
        $('#ss_menubar_initiator_btn').html(ss_menubar_initiator_btn_tmpl({ initiator: "Initiator" }));
        $("#ss_menubar_initiator_btn").bind({
            click:function(){
                // alert("Initiator!");
                $("#ss_menubar_initiator_icon").toggleClass("main_icon_f_6_8 main_icon_e_6_8");
            }
        });

        // Time button
        var ss_menubar_time_btn_tmpl = kendo.template($('#ss_menubar_time_btn_tmpl').html());
        $('#ss_menubar_time_btn').html(ss_menubar_time_btn_tmpl({ time: "Time" }));
        $("#ss_menubar_time_btn").bind({
            click:function(){
                // alert("Time!");
                SmartStream.setOrderParam();// = !SmartStream.getOrderParam();
                $("#ss_menubar_time_icon").toggleClass("main_icon_f_6_8 main_icon_e_6_8");
                SmartStream.refreshListView(true,true);//no cache
                SmartStream.setIsMoved(false);
            }
        });
        // search view
        var ss_search_view_tmpl = kendo.template($('#ss_search_view_tmpl').html());
        var searchOptions = {keywords: "Keywords",
                             communities: "Communities",
                             search: "Search",
                             to: "to",
                             time: "Time" }
        $("#ss_search_view").html(ss_search_view_tmpl(searchOptions));
        $("#ss_search_btn").bind({
            click:function(){
                var ss_keyword = $("#ss_search_keywords_input").val();
                var ss_comm    = $("#ss_search_comm_input").val();
                var ss_from    = $("#ss_search_date_from").val();
                var ss_to      = $("#ss_search_date_to").val();
                var ss_ResultNum = "0";
                if(ss_keyword.trim()=="") {
                    $("#ss_search_keywords_input").kendoTooltip({
                        content: 'Please input the keywords.',
                        position: "right",
                        autoHide: false,
                        showOn: false
                    });
                    $("#ss_search_keywords_input").data('kendoTooltip').show();
                    return ;
                }
                var ss_search_view_lable_tmpl = kendo.template($('#ss_search_view_lable_tmpl').html());
                /*
                request.pageSize,
                offset  :   request.offset,
                type    :   request.type,
                tid     :   request.targetId
                */

                var _data = {key:ss_keyword,pageSize:10,type:"U",
                    sync:true};
                /*
                
                    offset:ss_from,
                    targetId:ss_comm,
                    
                */
                SmartStream.setMaxData([]) ;
                Workport.StreamAPI.searchStream(function(_d,_code){
                        console.log(_d);
                        if(!_d){
                            Workport.utils.alertMsg("", 'network error!', function(_data){});
                            return ;
                        }
                        if(_d.notification==null||_d.notification==""){
                            //ss_viewModel_max.ss_topic_max_ds.read();
                            //return;
                        }else {
                            SmartStream.setMaxData(_d.notification);
                            ss_ResultNum = _d.notification.length;
                        }
                        ss_viewModel_max.ss_topic_max_ds.read();
                        
                        var resultLabel = {backToAll: "Back to all",
                                    resultNum: ss_ResultNum,
                                    resultsFor: "Results For",
                                    keyword_input: ss_keyword }
                        $("#ss_search_view_lable").html(ss_search_view_lable_tmpl(resultLabel));
                        $('#ss_view').highlight(ss_keyword);

                        $("#ss_search_view_lable").show();

                        $("#ss_search_result_back").bind({
                            click:function(){
                                // alert("back clicked!");

                                $("#ss_search_view").hide();
                                $("#ss_search_view_lable").hide();
                                $("#ss_search_keywords_input").val("");
                                $("#ss_search_view_lable").empty();
                                SmartStream.refreshListView(false,true);//cache
                            }
                        });
                },_data);


                

            }
        });
        $('#ss_search_keywords_input').bind({
            keypress : function (event) {
                if (event.keyCode == 13) {
                    var ss_keyword = $("#ss_search_keywords_input").val();
                    var ss_comm    = $("#ss_search_comm_input").val();
                    var ss_from    = $("#ss_search_date_from").val();
                    var ss_to      = $("#ss_search_date_to").val();
                    var ss_ResultNum = "0";
                    if(ss_keyword.trim()=="") {
                        $("#ss_search_keywords_input").kendoTooltip({
                            content: 'Please input the keywords.',
                            position: "right",
                            showOn: false
                        });
                        $("#ss_search_keywords_input").data('kendoTooltip').show();
                        return ;
                    }
                    var ss_search_view_lable_tmpl = kendo.template($('#ss_search_view_lable_tmpl').html());
                    /*
                     request.pageSize,
                     offset  :   request.offset,
                     type    :   request.type,
                     tid     :   request.targetId
                     */
                    var _data = {key:ss_keyword,pageSize:10,type:"U",
                        sync:true};
                    /*
                     offset:ss_from,
                     targetId:ss_comm,
                     */
                    SmartStream.setMaxData([]) ;
                    Workport.StreamAPI.searchStream(function(_d,_code){
                        console.log(_d);
                        if(!_d){
                            Workport.utils.alertMsg("", 'network error!', function(_data){});
                            return ;
                        }
                        if(_d.notification==null||_d.notification==""){
                            //ss_viewModel_max.ss_topic_max_ds.read();
                            //return;
                        }else {
                            SmartStream.setMaxData(_d.notification);
                            ss_ResultNum = _d.notification.length;
                        }
                        ss_viewModel_max.ss_topic_max_ds.read();

                        var resultLabel = {backToAll: "Back to all",
                            resultNum: ss_ResultNum,
                            resultsFor: "Results For",
                            keyword_input: ss_keyword }
                        $("#ss_search_view_lable").html(ss_search_view_lable_tmpl(resultLabel));
                        $('#ss_view').highlight(ss_keyword);

                        $("#ss_search_view_lable").show();

                        $("#ss_search_result_back").bind({
                            click:function(){
                                // alert("back clicked!");

                                $("#ss_search_view").hide();
                                $("#ss_search_view_lable").hide();
                                $("#ss_search_keywords_input").val("");
                                $("#ss_search_view_lable").empty();
                                SmartStream.refreshListView(false,true);//cache
                            }
                        });
                    },_data);
                }
            }
        });

        // date picker
        $("#ss_search_date_from").kendoDatePicker();
        $("#ss_search_date_to").kendoDatePicker();



        /*************   Tang's source code begin    **************/

        //bind topics template
        function bindListView(isMax,isChangeWidth){

            // SmartStream.getHideComponent() = !isMax;

            var ss_tmpl_sel;
            if(isMax){

                ss_tmpl_sel = "ss_tmpl_topics_max";
                // bind topics max viewmodel
                SmartStream.bindMaxTopicViewModel("#ss_view",ss_tmpl_sel);

                // bindCommentEvent();

            } else {


                ss_tmpl_sel = "ss_tmpl_topics_min";
                // bind topics min viewmodel
                SmartStream.bindMinTopicViewModel("#ss_view",ss_tmpl_sel);

            }
            if (isChangeWidth) {
                ss_view.toggleClass("wp_w_768");
                ss_view.toggleClass("wp_w_256");
            };
        };
        $('#wp_homepage_smartstream').appendTo('#smartsteam');
        /*$("#ss_menubar_share_btn").kendoTooltip({
            content: 'Click here to share your first Activity.' ,
            position: "bottom",
            autoHide: false,
            showOn: false
        });
        $('#ss_menubar_share_btn').bind({
            click:function(e){
                //HomePage_Scrollable.zoom(0);
                return;
            }
        });*/
//        $("#ss_menubar_share_btn").data('kendoTooltip').show();
        bindListView(false,true);

        $("#ss_view").scroll(function(e){onDataDivScroll($(e.target));e.stopPropagation();});
        function onDataDivScroll(element){
            var n1 = parseInt(element.get(0).scrollTop);
            var n2 = parseInt(element.get(0).clientHeight);
            var n3 = parseInt(element.get(0).scrollHeight);

            if (n1+n2==n3&&SmartStream.getIsMoved()) {

                // bottom next page
                SmartStream.refreshListView(false,false);//cache
                SmartStream.setIsMoved(false);
            } else if(n1 == 0&&SmartStream.getIsMoved()) {
                // top refresh
                SmartStream.refreshListView(true,false);//cache
                SmartStream.setIsMoved(false);
            }else {
                /*
                var top_load='<div id="ss_load_top_view" align="center" ><img src="imgs/loading.gif"></img></div>';
                var top_bottom = '<div id="ss_load_bottom_view" align="center" class="wp_h_20"><img src="imgs/loading.gif"></img></div>'

                if($('#ss_load_top_view').length==0){

                    sslog('-----------------top------------------');
                    $(top_load).insertBefore($('#ss_view .ss_border_1 :first'));
                    $('#ss_load_top_view').css({
                        "left":$('#ss_view').width()/2
                    });
                }
                if($('#ss_load_bottom_view').length==0){
                    sslog('-----------------bottom------------------');

                    $(top_bottom).appendTo($('#ss_view'));
                    $('#ss_load_bottom_view').css({
                        "left":$('#ss_view').width()/2
                    });
                    return ;
                }

                */
                SmartStream.setIsMoved(true);
            }
         };

});

</script>







